package com.hezhi.project.module.teacherClasses.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hezhi.project.module.teacherClasses.domain.TeacherClasses;
import com.hezhi.project.module.teacherClasses.service.ITeacherClassesService;
import com.hezhi.framework.web.controller.BaseController;
import com.hezhi.framework.web.page.TableDataInfo;
import com.hezhi.framework.web.domain.AjaxResult;

/**
 * 教师与班级绑定 信息操作处理
 * 
 * @author hezhi
 * @date 2018-08-17
 */
@Controller
@RequestMapping("/module/teacherClasses")
public class TeacherClassesController extends BaseController
{
    private String prefix = "module/teacherClasses";
	
	@Autowired
	private ITeacherClassesService teacherClassesService;
	
	@RequiresPermissions("module:teacherClasses:view")
	@GetMapping()
	public String teacherClasses()
	{
	    return prefix + "/teacherClasses";
	}
	
	/**
	 * 查询教师与班级绑定列表
	 */
	@RequiresPermissions("module:teacherClasses:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TeacherClasses teacherClasses)
	{
		startPage();
        List<TeacherClasses> list = teacherClassesService.selectTeacherClassesList(teacherClasses);
		return getDataTable(list);
	}
	
	/**
	 * 新增教师与班级绑定
	 */
	@RequiresPermissions("module:teacherClasses:add")
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改教师与班级绑定
	 */
	@RequiresPermissions("module:teacherClasses:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, Model model)
	{
		TeacherClasses teacherClasses = teacherClassesService.selectTeacherClassesById(id);
		model.addAttribute("teacherClasses", teacherClasses);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存教师与班级绑定
	 */
	@RequiresPermissions("module:teacherClasses:save")
	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(TeacherClasses teacherClasses)
	{
		if (teacherClassesService.saveTeacherClasses(teacherClasses) > 0)
		{
			return success();
		}
		return error();
	}
	
	/**
	 * 删除教师与班级绑定
	 */
	@RequiresPermissions("module:teacherClasses:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		int rows = teacherClassesService.deleteTeacherClassesByIds(ids);
		if (rows > 0)
        {
            return success();
        }
        return error();
	}
	
}
